package com.shouer.doc.widget;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.shouer.doc.R;
import com.shouer.doc.common.util.DateFormatUtil;

import java.text.ParseException;

/**
 * Created by ZXL on 2016/12/26.
 */

public class ShouerNotificationToast extends Toast{

    private View mView;

    public ShouerNotificationToast(Context context) {
        super(context);
    }

    @Override
    public void setView(View view) {
       super.setView(view);
        this.mView=view;
    }

    public void setTitle(String title)
    {
        if (null!=mView)
        {
            ((TextView)mView.findViewById(R.id.title)).setText(title);
        }
    }

    public void setContent(String content)
    {

        if (null!=mView)
        {
            ((TextView)mView.findViewById(R.id.content)).setText(content);
        }
    }

    public void setTime()
    {
        if (null!=mView)
        {
            ((TextView)mView.findViewById(R.id.time)).setText(DateFormatUtil.longToString(System.currentTimeMillis(),"HH:mm"));
        }
    }

    public static class Builder{

        private final Context context;
        private View mView;
        private String title;
        private String content;
        private int gravity;
        private int duration;

        public Builder(Context context) {
            this.context = context;
        }

        public Builder setmView(int  mViewResId) {
            this.mView = LayoutInflater.from(context).inflate(mViewResId,null);
            return this;
        }

        public Builder setTitle(String title) {
            this.title = title;
            return this;
        }

        public Builder setContent(String content) {
            this.content = content;
            return this;
        }

        public Builder setGravity(int gravity) {
            this.gravity = gravity;
            return this;
        }

        public Builder setDuration(int duration) {
            this.duration = duration;
            return this;
        }

        public ShouerNotificationToast createToast()
        {
            ((TextView)mView.findViewById(R.id.title)).setText(title);
            ((TextView)mView.findViewById(R.id.content)).setText(content);
            ((TextView)mView.findViewById(R.id.time)).setText(DateFormatUtil.longToString(System.currentTimeMillis(),"HH:mm"));
            ShouerNotificationToast toast = new ShouerNotificationToast(context);
            toast.setGravity(gravity, 0, 0);
            toast.setDuration(duration);
            toast.setView(mView);
            return toast;
        }
    }
}
